package com.fr.lintcode;

import org.junit.Test;

/**
*作者：furong
*日期：2017年1月16日
*时间：下午4:10:53
*/
public class Q97 {
    /**
     * @param root: The root of binary tree.
     * @return: An integer.
     */
    public static int maxDepth = 0;

    public int maxDepth(TreeNode root) {
        check(root, 0);
        return maxDepth;
    }

    private void check(TreeNode node, int i) {
        if (node == null) {
            if (i > maxDepth) {
                maxDepth = i;
            }
            return;
        }
        check(node.left, i + 1);
        check(node.right, i + 1);
    }

    @Test
    public void testA() {
        TreeNode root = new TreeNode(0);
        TreeNode r1 = new TreeNode(1);
        TreeNode r2 = new TreeNode(2);
        TreeNode r3 = new TreeNode(3);
        TreeNode r4 = new TreeNode(4);
        TreeNode r5 = new TreeNode(5);
        root.left = r1;
        root.right = r2;
        r1.left = r3;
        r2.right = r5;
        r3.right = r4;
        System.out.println(maxDepth(root));
    }
}
